package org.rainbowinverted.charging.device.connect.ykc.server.handler;

import org.rainbowinverted.charging.device.connect.ykc.server.attribute.DeviceInfo;
import org.rainbowinverted.charging.device.connect.ykc.server.constants.ChannelAttributeKeyConstants;
import org.rainbowinverted.charging.device.connect.ykc.server.message.in.YkcMessageIn;
import org.rainbowinverted.charging.device.connect.ykc.server.message.out.YkcMessageOut;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 设备状态处理器
 * @author hehuaiping
 */
@Component
public class YkcDeviceStatusHandler extends YkcAbstractHandler<Void, YkcMessageOut>{
    @Override
    public void read(ChannelHandlerContext channel, YkcMessageIn message) {

    }

    @Override
    public void write(ByteBuf byteBuf, YkcMessageOut out) {

    }

    /**
     * 获取设备状态信息
     * @param deviceNo 设备编号
     * @return {@link DeviceInfo}
     */
    public DeviceInfo getDeviceStatusInfo(Long deviceNo) {
        ChannelHandlerContext channel = getChannel(deviceNo);
        if (Objects.isNull(channel)) {
            return null;
        }
        return channel.channel().attr(ChannelAttributeKeyConstants.CHANNEL_ATTR_DEVICE_INFO).get();
    }
}
